﻿using System.Collections.Specialized;
using DBFile.Core.Interfaces;
using DBFile.Providers.Impl;

namespace DBFile.Providers
{
    public class FileSystemProvider : DBFileProviderBase
    {
        protected override string  ProviderDescription
        {
            get { return ProviderDescriptionMessage; }
        }
                
        protected override void  OnAfterInitialize(NameValueCollection configValue)
        {
            this.RepositoryPath = GetConfigSettingOrThrow(configValue, RepositoryPathKey, RepositoryPathMissingMessage);
        }

        protected override IDBFileProvider Provider
        {
            get
            {
                lock (padLock)
                {
                    if (_provider == null)
                    {
                        _provider = new FileSystemClient(RepositoryPath);
                    }
                }
                return _provider;
            }
        }

        internal string RepositoryPath { get; private set; }
        internal bool UseCompression { get; private set; }

        private const string ProviderDescriptionMessage = "FileSystem DBFile Provider";
        private const string RepositoryPathKey = "repositoryPath";
        private const string RepositoryPathMissingMessage = "Repository Path is not specified";
    }
}
